// BDbus_BPA.cpp: implementation of the CBDbus_BPA class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "../../Include/Dat/BDbus_BPA.h"

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

CBDbus_BPA::CBDbus_BPA()
{
	m_chType = 'B';
	m_chSubType = 'D';
	m_chChangeCode = ' ';

	m_bridgrating = 0;
	m_bridgs = 0;
	m_invrtroper_stop = 0;
	m_rectoper_min = 0;
	m_smthg_reactr = 0;
	strcpy(m_strZone,"  \0");
	strcpy(m_strBusname_AC,"        \0");
	m_valvdrop = 0;

}

CBDbus_BPA::~CBDbus_BPA()
{

}

bool CBDbus_BPA::UpdateEx(char *buffer)
{
	bool bResult = CNode_BPA::UpdateEx(buffer);
	
	if (!bResult)
	{
		printf("Error in (CBus_BPA: UpdateEx): impossible!\n");
		return false;
	}

	strcpy(&buffer[18],m_strZone);
	strcpy(&buffer[20],"   ");
	IntToStr(m_bridgs,&buffer[23],2);
	DoubleToStr(m_smthg_reactr,&buffer[25],5,1);
	DoubleToStr(m_rectoper_min,&buffer[30],5,1);
	DoubleToStr(m_invrtroper_stop,&buffer[35],5,1);
	DoubleToStr(m_valvdrop,&buffer[40],5,1);
	DoubleToStr(m_bridgrating,&buffer[45],5,1);
	strcpy(&buffer[50],m_strBusname_AC);
	DoubleToStr(m_basekV_AC,&buffer[58],4);
	
	return true;

}

bool CBDbus_BPA::FillEx(char *buffer)
{
	int i;
//	printf("CBDBus_BPA::FillEx\n");
	bool bResult = CNode_BPA::FillEx(buffer);
	
	if (!bResult)
	{
		printf("Error in (CBus_BPA: FillEx): no basic information!\n");
		return false;
	}
	
	if (strlen(buffer)<19)
		return bResult;
	
	for(i=0;i<2;i++)
	{
		if(!buffer[18+i])
			break;
		else
			m_strZone[i] = buffer[18+i];
	}
	m_strZone[2] = '\0';
	if(i!=2)
		return true;

	m_bridgs = StrToInt(&buffer[23],2,1);
	if(EndOfSec(&buffer[23],2))
		return true;

	m_smthg_reactr = StrToDouble(&buffer[25],5,1);
	if(EndOfSec(&buffer[25],5))
		return true;

	m_rectoper_min = StrToDouble(&buffer[30],5,1);
	if(EndOfSec(&buffer[30],5))
		return true;
	
	m_invrtroper_stop = StrToDouble(&buffer[35],5,1);
	if(EndOfSec(&buffer[35],5))
		return true;

	m_valvdrop = StrToDouble(&buffer[40],5,1);
	if(EndOfSec(&buffer[40],5))
		return true;

	m_bridgrating = StrToDouble(&buffer[45],5,1);
	if(EndOfSec(&buffer[45],5))
		return true;

	for(i=0;i<8;i++)
	{
		if(!buffer[50+i])
			break;
		else
			m_strBusname_AC[i] = buffer[50+i];
	}
	m_strBusname_AC[8] = '\0';
	if(i!=8)
		return true;

	m_basekV_AC = StrToDouble(&buffer[58],4);
	if(EndOfSec(&buffer[58],4))
		return true;
	
	return true;
}

CBDbus_BPA::CBDbus_BPA(CBDbus_BPA &BDbusBPA):CNode_BPA(BDbusBPA)
{
	m_bridgs = BDbusBPA.m_bridgs;
	m_smthg_reactr = BDbusBPA.m_smthg_reactr;
	m_rectoper_min = BDbusBPA.m_rectoper_min;
	m_invrtroper_stop = BDbusBPA.m_invrtroper_stop;
	m_bridgrating = BDbusBPA.m_bridgrating;
	m_valvdrop = BDbusBPA.m_valvdrop;
	m_basekV_AC = BDbusBPA.m_basekV_AC;

	strcpy(m_strBusname_AC,BDbusBPA.m_strBusname_AC);
	strcpy(m_strZone,BDbusBPA.m_strZone);	

}
